#pragma once

struct ST_BODY
{
	std::string test;
	int m_idx;
};

struct ST_BODY2
{
	std::string test2;
	ST_BODY body;

};

class UserSession : public SSession
{
public :
	UserSession(NetworkModule* pNetworkModule):SSession(pNetworkModule)
	{}
	virtual ~UserSession() {}

	virtual void OnAccept()
	{
		__super::OnAccept();
		printf("User OnAccept\n");
	}

	virtual void OnConnect(const bool& result)
	{
		__super::OnConnect(result);
		printf("User OnConnect(%d)\n", result);
	}
	//virtual void OnSend(size_t size);
	virtual void OnRecv(int type, BYTE* pPacket, int size)
	{
		__super::OnRecv(type, pPacket, size);

		static int g_count=0;
		int recvCount=0;
		if(0==type)
		{

			ST_BODY* pBody = reinterpret_cast<ST_BODY*>(pPacket);
			printf( "%s %d\n", pBody->test.c_str(), pBody->m_idx);

			recvCount= pBody->m_idx;
		}
		else
		{
			ST_BODY2* pBody = reinterpret_cast<ST_BODY2*>(pPacket);
			printf( "%s %s %d\n", pBody->test2.c_str(), pBody->body.test.c_str(), pBody->body.m_idx);			

			recvCount= pBody->body.m_idx;
		}

		++g_count;
		if(recvCount!=g_count)
		{
			//printf( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%d %d \n", 
			//	recvCount, g_count );
		}
		//Send(type, pPacket, size);

		Send(type, pPacket, size);
	}

	virtual void OnDisconnect()
	{
		printf("User OnDisconnect\n");
	}
};

class MyNetworkModule : public NetworkModule
{
public:
	MyNetworkModule():NetworkModule()
	{
	}

	virtual ~MyNetworkModule(){}
	virtual SSession* GetNewSession()
	{
		return new UserSession(this);
	}
};
